<?php

namespace App\Livewire;

use App\Models\ServerModel;
use Livewire\Attributes\Computed;
use Livewire\Component;

class ServerBaseInfo extends Component
{
    public $ip;

    public function mount($ip)
    {
        $this->ip = $ip;
    }

    #[Computed]
    public function server()
    {
        return ServerModel::query()->where('ip_address', '=', $this->ip)->first();
    }

    #[Computed]
    public function status()
    {
        return true;
    }

    #[Computed]
    public function activeSessionsCounter()
    {
        /** @var ServerModel */
        return ServerModel::query()->where('ip_address', '=', $this->ip)
            ->first()
            ->sessions()->where('active', '=', 1)->count();
    }

    public function render()
    {
        return view('livewire.server.server-base-info');
    }
}
